package com.gykfbxxh.imovie.custom.view;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.gykfbxxh.imovie.AppApplication;
import com.gykfbxxh.imovie.R;


/**
 * 底部加载更多view
 * Created by xuxinghai on 2016/7/24.
 */
public class LoadMoreView extends LinearLayout {

    private View loadPageView;
    private View errorPageView;
    private View emptyPageView;
    private TextView loadingTv;//加载提示
    private TextView errorTv;//错误提示
    private TextView emptyTv;
    private View placeHolderView;
    private ProgressBar progressBar;


    public LoadMoreView(Context context) {
        super(context);
        initView(context);
    }

    public LoadMoreView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public LoadMoreView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    public void initView(Context context) {

        inflate(context, R.layout.layout_loadmore_footerview, this);
        loadPageView = findViewById(R.id.loading_page);
        errorPageView = findViewById(R.id.load_error_page);
        emptyPageView = findViewById(R.id.load_empty_page);
        loadingTv = (TextView) findViewById(R.id.tv_loading_text);
        errorTv = (TextView) findViewById(R.id.error_text);
        emptyTv = (TextView) findViewById(R.id.empt_text);

        progressBar = (ProgressBar)findViewById(R.id.pb_loading_progress);
        //progressBar.setIndeterminateDrawable(getResources().getDrawable(R.drawable.infor_home_loading));
        //progressBar.setProgressDrawable(getResources().getDrawable(R.drawable.infor_home_loading));


    }

    /**
     * 展示加载完成
     */
    public void showSuccess(){
        this.setVisibility(View.GONE);
    }

    /**
     * 展示正在加载
     */
    public void showLoading(String msg){
        if(loadingTv == null){
            return;
        }
        if(TextUtils.isEmpty(msg)){
            loadingTv.setText(AppApplication.getInstance().getString(R.string.loading));
        }else{
            loadingTv.setText(msg);
        }
        this.setVisibility(View.VISIBLE);
        this.loadPageView.setVisibility(View.VISIBLE);
        this.emptyPageView.setVisibility(View.GONE);
        this.errorPageView.setVisibility(View.GONE);
    }

    /**
     * 展示正在加载
     */
    public void showErrorPage(String msg){
        if(errorTv == null){
            return;
        }
        if(TextUtils.isEmpty(msg)){
            errorTv.setText(AppApplication.getInstance().getString(R.string.flusherror));
        }else{
            errorTv.setText(msg);
        }
        this.setVisibility(View.VISIBLE);

        this.loadPageView.setVisibility(View.GONE);
        this.emptyPageView.setVisibility(View.GONE);
        this.errorPageView.setVisibility(View.VISIBLE);
    }

    /**
     * 展示正在加载
     */
    public void showEmptyPage(){
        this.setVisibility(View.VISIBLE);
        if(loadPageView == null){
            return;
        }
        this.loadPageView.setVisibility(View.GONE);
        this.emptyPageView.setVisibility(View.VISIBLE);
        this.errorPageView.setVisibility(View.GONE);
    }

    /**
     * 展示空数据加载
     */
    public void showEmptyPage(String msg){
        this.setVisibility(View.VISIBLE);
        if(loadPageView == null){
            return;
        }
        this.loadPageView.setVisibility(View.GONE);
        this.emptyPageView.setVisibility(View.VISIBLE);
        if(!TextUtils.isEmpty(msg)) this.emptyTv.setText(msg);
        this.errorPageView.setVisibility(View.GONE);
    }




    /**
     * 设置错误点击
     * @param onClickListener
     */
    public void setErrorPageOnClickListener(OnClickListener onClickListener){
        if(errorPageView != null){
            this.errorPageView.setOnClickListener(onClickListener);
        }
    }

    /**
     * 设置空数据点击
     * @param onClickListener
     */
    public void setEmptyPageOnClickListener(OnClickListener onClickListener){
        if(emptyPageView != null){
            this.emptyPageView.setOnClickListener(onClickListener);
        }

    }


}
